package com.chengjj.kings.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;

/**
 * @Author: 成俊杰
 * @CreateDate: 2019/3/1
 * @Version: 1.0
 * @Description: spring-session 分布式session配置
 */

/**
 * session过期时间  如果部署多机环境,需要打开注释
 */
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 1800)
@ConditionalOnProperty(prefix = "kings", name = "spring-session-open", havingValue = "true", matchIfMissing = false)
public class SpringSessionConfig {

    /**
     * 使用方式
     *
     * @ResponseBody
     *     @RequestMapping(value = "/session")
     *     public Map<String, Object> getSession(HttpServletRequest request) {
     *         request.getSession().setAttribute("username", "admin");
     *         Map<String, Object> map = new HashMap<String, Object>();
     *         map.put("sessionId", request.getSession().getId());
     *         return map;
     *     }
     *
     *     @ResponseBody
     *     @RequestMapping(value = "/get")
     *     public String get(HttpServletRequest request) {
     *         String userName = (String) request.getSession().getAttribute("username");
     *         return userName;
     *     }
     */
}
